<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class CompanyInsurance extends Page
{
       public $Image3 = null;
       public $btnCancel = null;
       public $btnSubmit = null;
       public $edPremium = null;
       public $lblPremium = null;
       public $edPhone = null;
       public $lblPhone = null;
       public $lblCoverage = null;
       public $edCoverage = null;
       public $edAgent = null;
       public $lblAgent = null;
       public $edInsurance = null;
       public $lblInsurance = null;
       public $edAddress = null;
       public $lblAddress = null;
       public $lblCompany = null;
       public $edCompany = null;
       public $edPolicy = null;
       public $lblPolicy = null;
       public $JTSiteTheme1 = null;
       function btnSubmitClick($sender, $params)
       {

       $result=mysql_query("select * from company_insurance_tbl where company_id='".$_SESSION['company_id']."'");
       $count=mysql_num_rows($result);
       if($count==0)
       {
       mysql_query("insert into company_insurance_tbl (company_id,
       policy_no,
       company_name,
       address,
       insurance_company,
       agent,
       contact_no,
       coverage_limits,
       premium)

       Values('".$_SESSION['company_id']."',
       '".$this->edPolicy->Text."',
       '".$this->edCompany->Text."',
       '".$this->edAddress->Text."',
       '".$this->edInsurance->Text."',
       '".$this->edAgent->Text."',
       '".$this->edPhone->Text."',
       '".$this->edCoverage->Text."',
       '".$this->edPremium->Text."')") or die ("insert insurance - " . mysql_error());
       }
       else
       {
       mysql_query("update company_insurance_tbl set
       policy_no='".$this->edPolicy->Text."',
       company_name='".$this->edCompany->Text."',
       address='".$this->edAddress->Text."',
       insurance_company='".$this->edInsurance->Text."',
       agent='".$this->edAgent->Text."',
       contact_no='".$this->edPhone->Text."',
       coverage_limits='".$this->edCoverage->Text."',
       premium='".$this->edPremium->Text."'
       where company_id='".$_SESSION['company_id']."'") or die ("update insurance - " . mysql_error());
       }
       redirect('vehicle_list.php?company_id='.$_SESSION['company_id']);


       }


       function btnCancelClick($sender, $params)
       {
       redirect('vehicle_list.php?company_id='.$_SESSION['company_id']);
       }

       function CompanyInsuranceCreate($sender, $params)
       {

       $query = "select * from company_insurance_tbl where company_id='".$_SESSION['company_id']."'";
       $result_show = mysql_query($query)or die("SELECT INSURANCE - " . mysql_error());
       $row= mysql_fetch_array($result_show);

       $this->edPolicy->Text = $row['policy_no'];
       $this->edCompany->Text = $row['company_name'];
       $this->edAddress->Text = $row['address'];
       $this->edInsurance->Text = $row['insurance_company'];
       $this->edAgent->Text = $row['agent'];
       $this->edPhone->Text = $row['contact_no'];
       $this->edCoverage->Text = $row['coverage_limits'];
       $this->edPremium->Text = $row['premium'];

       }

}

global $application;

global $CompanyInsurance;

//Creates the form
$CompanyInsurance=new CompanyInsurance($application);

//Read from resource file
$CompanyInsurance->loadResource(__FILE__);

//Shows the form
$CompanyInsurance->show();

?>